<template>
  <div>
    <div
      class="wrapper-container"
      style="display: flex; flex-direction: column; width: 100%;"
    >
      <div class="search-container">
        <div class="search-container-left" style="display: flex;align-items: center;">
          <div
            class="search-container-item"
            v-for="(select, index) in selectList"
            :key="index"
          >
            <div v-if="select.type === 'select'" class="box">
              <span v-show="select.name">{{ select.name }}</span>
              <el-select
                v-model="select.val"
                style="width: 120px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
            <div v-if="select.type === 'jys'" class="box">
              <span v-show="select.name">{{ select.name }}</span>
              <el-popover
                trigger="click"
                placement="bottom"
                v-model="showUnitTreeJys"
                style="cursor: pointer"
                width="120"
              >
                <div style="max-height: 260px; overflow-y: auto">
                  <el-tree
                    size="mini"
                    default-expand-all
                    node-key="id"
                    :data="select.valList"
                    :expand-on-click-node="false"
                    :props="props"
                    @node-click="toShowUnitInfoJys"
                  >
                  </el-tree>
                </div>
                <el-input
                  size="mini"
                  slot="reference"
                  v-model="kcfzdw"
                  class="selectTree"
                  clearable
                  style="width: 120px"
                  suffix-icon="el-icon-arrow-down"
                >
                </el-input>
              </el-popover>
              <!--<el-select-->
                <!--v-model="select.val"-->
                <!--style="width: 120px"-->
                <!--size="mini"-->
                <!--placeholder="请选择"-->
                <!--clearable-->
              <!--&gt;-->
                <!--<el-option-->
                  <!--v-for="item in select.valList"-->
                  <!--:key="item.id"-->
                  <!--:label="item.deptName"-->
                  <!--:value="item.id"-->
                <!--&gt;-->
                <!--</el-option>-->
              <!--</el-select>-->
            </div>
            <div v-if="select.type === 'selectTree'" class="box">
              <span v-show="select.name">{{ select.name }}</span>
              <el-popover
                trigger="click"
                placement="bottom"
                v-model="showUnitTree"
                style="cursor: pointer;"
                width="120">
                <div style="max-height: 260px;overflow-y: auto;">
                <el-tree
                      default-expand-all
                      node-key="id"
                      :data="select.valList"
                      :expand-on-click-node="false"
                      :props="props"
                      @node-click="toShowUnitInfo">
                </el-tree>
                </div>
                <el-input slot="reference" v-model="select.val" class="selectTree"
                    clearable style="width: 120px;" suffix-icon="el-icon-arrow-down">
                </el-input>
              </el-popover>
            </div>
            <div v-if="select.type === 'more_select'" class="box" style="width:300px">
              <span v-show="select.name">{{ select.name }}</span>

              <el-select
                v-model="select.val1"
                style="width: 100px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              -
              <el-select
                v-model="select.val2"
                style="width: 100px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>

          </div>
          <div class="search-button" style="margin-left: 120px" @click="queryClassList()">
            <img src="../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
        </div>

        <div class="export-top" style="float: right;margin-right:10px" @click="exportData()">
          <img src="../../../../assets/assessment/icon-export.png" alt="" />
          <span>&ensp;导出Excel</span>
        </div>

      </div>
    </div>


    <div class="body-manual-container" style="width: calc(100% - 20px);
    margin: 0 auto;
    overflow-x: auto;">
      <div>
        <ul>
          <li style="display: flex; align-items: center">
            <div class="block-show"><div style="width: 70px;text-align: center;">节次</div></div>
            <div class="block-show"><div style="width: 70px;text-align: center;">日期</div></div>
            <div class="block-item">
              <div class="top">星期一</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期二</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期三</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期四</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期五</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期六</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
            <div class="block-item">
              <div class="top">星期日</div>
              <div class="bottom">
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
                <div>8</div>
                <div>9</div>
                <div>10</div>
              </div>
            </div>
          </li>
          <li v-for="(item, index) in tableList" :key="index">
            <div style="display: flex">
              <div class="block-border"><div class="block-cont">{{ item.zc }}</div></div>
              <div class="block-border"><div class="block-cont">{{ item.rq }}</div></div>
              <div class="block-cont-item">
                <div v-for="da in item.xq1"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq2"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq3"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq4"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq5"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq6"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
              <div class="block-cont-item">
                <div v-for="da in item.xq7"><span @click="toShowDetails(item.rq, da)">{{ da.kc }}</span></div>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import tablelist from "@/views/comonents/tablelist";
import ButtonItem from "@/components/ButtonItem.vue";
import SelectItem from "@/components/SelectItem.vue";

import {queryCommonDept, queryCommonJysDept, queryCommonXueqi, kscx_kcb_bm, kscx_kcb_bm_export, queryDefaultXueQi} from "@/api/trainingManagement/place.js";

export default {
  components: {
    tablelist,
    ButtonItem,
    SelectItem,
  },
  data() {
    return {
      props:{
        children: "children",
        label: "name",
      },
      showUnitTreeJys:false,
      treeOptionList: [], //单位下拉树
      showUnitTree: false, //
      kcfzdw: '',
      unitId: "", //单位id
      tableList: [], //
      selectList: [
        {
          type: "select",
          name: "学期:",
          val: "",
          valList: [],
        },
        {
          type: "selectTree",
          name: "承担单位:",
          val: "",
          valList: [],
        },
        {
          type: "jys",
          name: "教研室:",
          val: "",
          valList: [],
        },
        {
          type: "more_select",
          name: "周次:",
          val1: "",
          val2: "",
          valList: [{ label: "1", value: "1" },{ label: "2", value: "2" },{ label: "3", value: "3" },
      { label: "4", value: "4" },{ label: "5", value: "5" },{ label: "6", value: "6" },{ label: "7", value: "7" },{ label: "8", value: "8" },{ label: "9", value: "9" },
      { label: "10", value: "10" },{ label: "11", value: "11" },{ label: "12", value: "12" },{ label: "13", value: "13" },
      { label: "14", value: "14" },{ label: "15", value: "15" },{ label: "16", value: "16" },
      { label: "17", value: "17" },{ label: "18", value: "18" },{ label: "19", value: "19" },{ label: "20", value: "20" }],
        },
      ],
    };
  },
  created() {},
  mounted() {
    this.getDefaultXueQi();
    this.queryCommonDept();
    this.queryJYS();
    this.queryCommonXueqi();
  },
  methods: {
    toShowUnitInfoJys(data){
      this.kcfzdw = data.name;
      this.xiId = data.id;
      this.showUnitTreeJys = false;
    },
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.selectList[0].val = res.data.data;
          // this.semester = res.data.data;
        }
      }).then(()=>{
        // this.queryDAteClass()
      })
    },
    // 导出培养计划
    exportData() {
      var xq = this.selectList[0].val;
      var cddw = this.selectList[1].val;
      var jys = this.unitId;
      var zcSart = this.selectList[3].val1;
      var zcEnd = this.selectList[3].val2;
      kscx_kcb_bm_export(xq, cddw, jys, zcSart, zcEnd).then((res) => {
           /** 获取生成设置好的文件名 */
        var filename = res.headers["content-disposition"];
        filename = filename.split("=")[1];
        // 我看好多博客此处没有再次编码，我这里不重新编码，文件名称总是乱码
        filename = escape(filename);
        filename = decodeURIComponent(filename, "utf-8");
        console.log(filename);
        console.log(res.data);
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "课表.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    async queryClassList() {
      var xq = this.selectList[0].val;
      var cddw = this.unitId ;
      var jys = this.selectList[2].val;
      var zcSart = this.selectList[3].val1;
      var zcEnd = this.selectList[3].val2;
      const res = await kscx_kcb_bm(xq, cddw, jys, zcSart, zcEnd);
      if (res.data.code == 200) {
         this.tableList= res.data.data;
      }
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
         this.selectList[0].valList = res.data.data;
        // this.selectList[0].val = this.selectList[0].valList[0].name;
      }
    },
    async queryJYS() {
      const res = await queryCommonJysDept();
      if (res.data.code == 200) {
        this.selectList[2].valList = res.data.data;
      }
    },
    async queryCommonDept() {
      const res = await queryCommonDept();
      if (res.data.code == 200) {
        this.selectList[1].valList = res.data.data;
        // this.selectList[1].val = this.selectList[1].valList[0].name;
        // this.unitId = this.selectList[1].valList[0].id;
      }
    },
    toShowUnitInfo(data) {
      this.selectList[1].val = data.name;
      this.unitId = data.id;
      this.showUnitTree = false;
        // this.query();
      },
      // 跳转详情页
      toShowDetails(rq, row) {
        if (row.kc != "" && row.kc != null) {
           this.$router.push({
            path: "/admin/course/departmentScheduleDetails",
            query: {
              date: rq,
              kcmc: row.kc
            }
          })
        }

      }
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/text.less";
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 14%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      // margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.search-button {
  width: 77px;
  height: 28px;
  line-height: 28px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  > span {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }
  > img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
  }
}

.body-manual-container {
  > div:nth-child(1) {
    width: 100%;
    height: calc(100vh - 220px);
    border: 1px solid rgba(0, 76, 167, 0.8);
    border-radius: 6px;
    overflow: auto;
    margin: 30px auto 0;
    ul {
      list-style: none;
      li:nth-child(n) {
        // border-bottom: 1px solid rgba(0, 76, 167, 0.4);
        height: auto;
      }
    }
  }
}

.export-right {
  display: flex;
  align-items: center;
  justify-content: end;
  margin-right: 70px;
  margin-top: -50px;
}

.block-show {
  width: 70px;
  height: 120px;
  border-right: 1px solid rgba(0, 76, 167, 0.4);
  border-bottom: 1px solid rgba(0, 76, 167, 0.4);
  color: #004ca7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.block-border {
  border-bottom: 1px solid rgba(0, 76, 167, 0.4);
}
.block-item {
  width: 400px;
  height: 120px;
  border-right: 1px solid rgba(0, 76, 167, 0.4);
  border-bottom: 1px solid rgba(0, 76, 167, 0.4);
  color: #004ca7;
  font-weight: bold;
  .top {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    border-bottom: 1px solid rgba(0, 76, 167, 0.4);
  }
  .bottom {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    width: 400px;
    > div {
      height: 60px;
      width: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-right: 1px solid rgba(0, 76, 167, 0.4);
    }
    > div:nth-last-child(1) {
      border-right: 0;
    }
  }
}
.block-item:nth-last-child(1) {
  border-right: 0;
}

.block-cont {
  width: 70px;
  height: 180px;
  border-right: 1px solid rgba(0, 76, 167, 0.4);
  color: #004ca7;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-cont-item-all {
  width: 400px;
  border-right: 1px solid;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-right: 1px solid rgba(0, 76, 167, 0.4);
  color: #004ca7;
}

.block-cont-item {
  display: flex;
  width: 400px;
  > div {
    width: 40px;
    border-right: 1px solid rgba(0, 76, 167, 0.4);
    border-bottom:1px solid rgba(0, 76, 167, 0.4);
    color: #004ca7;
    word-wrap: break-word;
    writing-mode: vertical-lr;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: underline;
    cursor: pointer;
  }
}

.undeLine {
  text-decoration: underline;
  cursor: pointer;
}

.export-top {
  cursor: pointer;
  width: 127px;
  height: 28px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 4px;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  flex-direction: row;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  > img {
    width: 17px;
    height: 17px;
  }
  > span {
    color: #f3b815;
  }
}

/deep/ .el-tree-node {
  color: #004ca7;
}
</style>
